﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
namespace wsn.dao
{
    public  class DataDao
    {
        //保存数据到数据库中
        public void save(wsn.ap.AccessPointData data)
        {
            //to to            
            string query = "insert into AccPoiData(sensor_data,sensor_hopcount,sensor_id) values('" + data.Sensor_Data1 + "','"
                            + data.Sensor_Hopcout + "','" + data.Sensor.Id + "'";
            //Daofactory.db.ExeNoneQuery(query);
        }

        public String getSensorData(String ipv6)
        {
            string query = "select id from sensor where ipv6='" + ipv6 + "'";
            int id=-1;
            MySqlDataReader reader = Daofactory.db.ExeQuery(query);
            if (reader.Read())
            {
                id = reader.GetInt32(0);
            }
            query = "select sensor_data from  AccPoiData where sensor_id='" + id + "'";
            reader=Daofactory.db.ExeQuery(query);
            string sensor_data=" ";
            if (reader.Read())
            {
                sensor_data = reader.GetString(0);
            }
            reader.Close();
            return sensor_data;
        }
    }
}
